package com.system.demo.controller.competition;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.system.demo.entity.DTO.SubmitApplicationInfo;
import com.system.demo.entity.database.SubmitApplication;
import com.system.demo.service.CompetitionService;
import com.system.demo.tool.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;


@RestController
@RequestMapping("/competition/student")
public class CompetitionController {

    @Autowired
    private CompetitionService competitionService;

    /**
     * 学生学科竞赛申报提交：
     *
     * @param submitApplicationInfo 前端提交的竞赛申请表单
     * @return 返回信息
     */
    @PostMapping
    @SaCheckPermission("CompApply")
    //该接口必须要登录才能使用
    //@SaCheckLogin
    public ResponseResult<?> submitApplication(@RequestBody SubmitApplicationInfo submitApplicationInfo){
        return competitionService.submitApplication(submitApplicationInfo);
    }

    /**
     * 学生查看审批结果：
     *
     * @return 返回查询信息
     */
    @GetMapping
    @SaCheckPermission("CompApply")
    public ResponseResult<?> getReviewResult(){
        return competitionService.getReviewResult();
    }

    /**
     * 学生参加竞赛获奖后上传获奖文件，申请认定等级
     *
     * @param file 获奖证书
     * @param rewardTitle 获奖全称
     * @return 返回信息
     */
    @PostMapping("/upload")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> uploadFile(@RequestParam Integer applicationId,
                                        @RequestParam("file") MultipartFile file,
                                        @RequestParam String rewardTitle,
                                        @RequestParam("awardDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime awardDate) {
        // 处理文件上传
        return competitionService.uploadFile(applicationId, file, rewardTitle, awardDate);
    }

    //未获奖（放弃认定）
    @GetMapping("/noReward")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> noReward(@RequestParam Integer applicationId){
        return competitionService.noReward(applicationId);
    }

    @PostMapping("/delete")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> deleteApplication(@RequestParam Integer applicationId) {
        return competitionService.deleteFile(applicationId);
    }

    @GetMapping("/getUploadFile")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> getUploadFile(@RequestParam Integer applicationId){
        return competitionService.getUploadFile(applicationId);
    }

    @PostMapping("/modifiedApplication")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> modifiedApplication(@RequestBody SubmitApplication submitApplication){
        return competitionService.modifiedApplication(submitApplication);
    }

    @GetMapping("/getCognizanceResult")
    @SaCheckPermission("CompApply")
    public ResponseResult<?> getCognizanceResult(@RequestParam Integer applicationId){
        return competitionService.getCognizanceResult(applicationId);
    }

}
